import axios from "axios";
import { message } from "ant-design-vue";

export function getHeaders () {
    return {

    }
}

export function Proxy (url, type) {
    return `${url}`;
}

export default function Send ({
    url,
    data,
    method = "get",
    headers,
    timeout,
    responseType,
    withCredentials,
    _config = {}
}) {
    let sendHeaders = getHeaders();

    sendHeaders["Content-Type"] = "application/json;charset=utf-8";

    const sendData = data || {};

    let config = {
        method,
        url,
        data: method === "post" ? sendData : {},
        params: method === "get" ? sendData : {},
        headers: headers ? Object.assign(sendHeaders, headers) : sendHeaders,
        timeout: timeout || 180000,
        withCredentials: withCredentials || true,
        responseType: responseType || "json",
        crossDomain: true,
        ..._config
    };

    return new Promise((resolve,reject) => {
        axios(config).then(res => {
            if (res.data.code!==0){
                message.warning(res.data.msg);
            }
            resolve(res.data)

        }).catch(e => {
            alert(e)
        })

    })

}
